home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zcssepr.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  6.2 KB  |  224 lines

  1. /* Copyright (C) 1994, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zcssepr.c,v 1.5 2000/09/19 19:00:53 lpd Exp $ */
  20. /* Separation color space support */
  21. #include "memory_.h"
  22. #include "ghost.h"
  23. #include "oper.h"
  24. #include "gsstruct.h"
  25. #include "gscolor.h"
  26. #include "gsmatrix.h"        /* for gxcolor2.h */
  27. #include "gscsepr.h"
  28. #include "gxcspace.h"
  29. #include "gxfixed.h"        /* ditto */
  30. #include "gxcolor2.h"
  31. #include "estack.h"
  32. #include "ialloc.h"
  33. #include "icsmap.h"
  34. #include "ifunc.h"
  35. #include "igstate.h"
  36. #include "iname.h"
  37. #include "ivmspace.h"
  38. #include "store.h"
  39.  
  40. /* Imported from gscsepr.c */
  41. extern const gs_color_space_type gs_color_space_type_Separation;
  42.  
  43. /* Forward references */
  44. private int separation_map1(P1(i_ctx_t *));
  45.  
  46. /* Define the separation cache size.  This makes many useful tint values */
  47. /* map to integer cache indices. */
  48. #define SEPARATION_CACHE_SIZE 360
  49.  
  50. /* Tint transform procedure that just consults the cache. */
  51. private int
  52. lookup_tint(const gs_separation_params * params, floatp tint, float *values)
  53. {
  54.     int m = cs_num_components((const gs_color_space *)¶ms->alt_space);
  55.     const gs_indexed_map *map = params->map;
  56.     int value_index =
  57.     (tint < 0 ? 0 : tint > 1 ? map->num_values - m :
  58.      (int)(tint * SEPARATION_CACHE_SIZE + 0.5) * m);
  59.     const float *pv = &map->values[value_index];
  60.  
  61.     memcpy(values, pv, sizeof(*values) * m);
  62.     return 0;
  63. }
  64.  
  65. /* <array> .setseparationspace - */
  66. /* The current color space is the alternate space for the separation space. */
  67. private int
  68. zsetseparationspace(i_ctx_t *i_ctx_p)
  69. {
  70.     os_ptr op = osp;
  71.     const ref *pcsa;
  72.     gs_color_space cs;
  73.     ref_colorspace cspace_old;
  74.     uint edepth = ref_stack_count(&e_stack);
  75.     gs_indexed_map *map;
  76.     ref sname;
  77.     int code;
  78.  
  79.     check_read_type(*op, t_array);
  80.     if (r_size(op) != 4)
  81.     return_error(e_rangecheck);
  82.     pcsa = op->value.const_refs + 1;
  83.     sname = *pcsa;
  84.     switch (r_type(&sname)) {
  85.     default:
  86.         return_error(e_typecheck);
  87.     case t_string:
  88.         code = name_from_string(&sname, &sname);
  89.         if (code < 0)
  90.         return code;
  91.         /* falls through */
  92.     case t_name:
  93.         break;
  94.     }
  95.     check_proc(pcsa[2]);
  96.     cs = *gs_currentcolorspace(igs);
  97.     if (!cs.type->can_be_alt_space)
  98.     return_error(e_rangecheck);
  99.     code = zcs_begin_map(i_ctx_p, &map, &pcsa[2], SEPARATION_CACHE_SIZE + 1,
  100.              (const gs_direct_color_space *)&cs,
  101.              separation_map1);
  102.     if (code < 0)
  103.     return code;
  104.     map->proc.tint_transform = lookup_tint;
  105.     /* See zcsindex.c for why we use memmove here. */
  106.     memmove(&cs.params.separation.alt_space, &cs,
  107.         sizeof(cs.params.separation.alt_space));
  108.     gs_cspace_init(&cs, &gs_color_space_type_Separation, NULL);
  109.     cs.params.separation.sname = name_index(&sname);
  110.     cs.params.separation.map = map;
  111.     cspace_old = istate->colorspace;
  112.     istate->colorspace.procs.special.separation.layer_name = pcsa[0];
  113.     istate->colorspace.procs.special.separation.tint_transform = pcsa[2];
  114.     code = gs_setcolorspace(igs, &cs);
  115.     if (code < 0) {
  116.     istate->colorspace = cspace_old;
  117.     ref_stack_pop_to(&e_stack, edepth);
  118.     return code;
  119.     }
  120.     pop(1);
  121.     return (ref_stack_count(&e_stack) == edepth ? 0 : o_push_estack);    /* installation will load the caches */
  122. }
  123.  
  124. /* Continuation procedure for saving transformed tint values. */
  125. private int
  126. separation_map1(i_ctx_t *i_ctx_p)
  127. {
  128.     os_ptr op = osp;
  129.     es_ptr ep = esp;
  130.     int i = (int)ep[csme_index].value.intval;
  131.  
  132.     if (i >= 0) {        /* i.e., not first time */
  133.     int m = (int)ep[csme_num_components].value.intval;
  134.     int code = float_params(op, m, &r_ptr(&ep[csme_map], gs_indexed_map)->values[i * m]);
  135.  
  136.     if (code < 0)
  137.         return code;
  138.     pop(m);
  139.     op -= m;
  140.     if (i == (int)ep[csme_hival].value.intval) {    /* All done. */
  141.         /*
  142.          * If the tint_transform procedure is a Function, recognize it
  143.          * as such now.
  144.          */
  145.         gs_function_t *pfn = ref_function(&ep[csme_proc]);
  146.  
  147.         if (pfn)
  148.         gs_cspace_set_sepr_function(gs_currentcolorspace(igs), pfn);
  149.         esp -= num_csme;
  150.         return o_pop_estack;
  151.     }
  152.     }
  153.     push(1);
  154.     ep[csme_index].value.intval = ++i;
  155.     make_real(op, i / (float)SEPARATION_CACHE_SIZE);
  156.     make_op_estack(ep + 1, separation_map1);
  157.     ep[2] = ep[csme_proc];    /* tint_transform */
  158.     esp = ep + 2;
  159.     return o_push_estack;
  160. }
  161.  
  162. /* - currentoverprint <bool> */
  163. private int
  164. zcurrentoverprint(i_ctx_t *i_ctx_p)
  165. {
  166.     os_ptr op = osp;
  167.  
  168.     push(1);
  169.     make_bool(op, gs_currentoverprint(igs));
  170.     return 0;
  171. }
  172.  
  173. /* <bool> setoverprint - */
  174. private int
  175. zsetoverprint(i_ctx_t *i_ctx_p)
  176. {
  177.     os_ptr op = osp;
  178.  
  179.     check_type(*op, t_boolean);
  180.     gs_setoverprint(igs, op->value.boolval);
  181.     pop(1);
  182.     return 0;
  183. }
  184.  
  185. /* - .currentoverprintmode <int> */
  186. private int
  187. zcurrentoverprintmode(i_ctx_t *i_ctx_p)
  188. {
  189.     os_ptr op = osp;
  190.  
  191.     push(1);
  192.     make_int(op, gs_currentoverprintmode(igs));
  193.     return 0;
  194. }
  195.  
  196. /* <int> .setoverprintmode - */
  197. private int
  198. zsetoverprintmode(i_ctx_t *i_ctx_p)
  199. {
  200.     os_ptr op = osp;
  201.     int param;
  202.     int code = int_param(op, max_int, ¶m);
  203.  
  204.     if (code < 0 || (code = gs_setoverprintmode(igs, param)) < 0)
  205.     return code;
  206.     pop(1);
  207.     return 0;
  208. }
  209.  
  210. /* ------ Initialization procedure ------ */
  211.  
  212. const op_def zcssepr_l2_op_defs[] =
  213. {
  214.     op_def_begin_level2(),
  215.     {"0currentoverprint", zcurrentoverprint},
  216.     {"0.currentoverprintmode", zcurrentoverprintmode},
  217.     {"1setoverprint", zsetoverprint},
  218.     {"1.setoverprintmode", zsetoverprintmode},
  219.     {"1.setseparationspace", zsetseparationspace},
  220.         /* Internal operators */
  221.     {"1%separation_map1", separation_map1},
  222.     op_def_end(0)
  223. };
  224.